package library.net.retrofit.response;

/**
 * @author Created by qiang.hou on 2017/11/20.
 * @version 1.0
 */
public class RxBaseResponse<T> {

    private final static int default_success_code = 200;

    private int code;
    private String message;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * @return if current request success
     */
    public boolean isSuccess() {
        return code == (defineSuccessCode() < 0 ? default_success_code : defineSuccessCode());
    }

    /**
     * @return success code
     */
    protected int defineSuccessCode() {
        return 0;
    }

    @Override
    public String toString() {
        return "RxBaseResponse{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
